<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.title.center_zhuyonghu"></spring:message></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <style type="text/css">
       
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                    <div class="input">
                    <div class="textalign1">用户<spring:message code="message.lable.username" /><spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="name" name="name" placeholder="用户<spring:message code="message.lable.username" />" maxlength="50" />
                    </div>
                    
                    <div class="textalign">用户<spring:message code="message.lable.userType" /><spring:message code="message.yanZheng.maoHao"/></div>
                        <div class="boxinput">
                           <select id="type" class="textinput">
	                           <option value=""><spring:message code="message.select.option"/></option>
								<c:if test="${ userTypeList != null }">
									<c:forEach items="${ userTypeList }" var="userType">
										<option value="${userType.key}">${userType.value}</option>
									</c:forEach>
								</c:if>
	                      </select>
                    </div>
                    <div class="textalign" ><ms:btn url='/sysUser/getZxUserList.html' ><button type="button" class="btn btn-success btn-sm" onclick="search();" id="selectDicCompType"><spring:message code="message.button.seachSpacing" /></button></ms:btn></div>
                    </div>
                </div>
            </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
            <div class="box box-warning bottongroup">
            <button type="button" class="btn btn-primary btn-sm" onclick="batchGroupAddComp()">选&nbsp; 择</button>
            <button type="button" class="btn btn-danger btn-sm"   onclick="closeDiv()">取&nbsp; 消</button>
        </div>
		
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    	
    //绑定回车
	$('#name,#type').bind('keydown', function(event) {
	if (event.keyCode == "13") {
    $('#selectDicCompType').click();
		}
	});	
		 $(function(){
			  $("#name").focus();//加载页面光标在第一个查询框内
			 
			 $('.form-inline :input').bind('keydown', function(event) {if (event.keyCode == "13") {search();}}).eq(0).focus();
		     $("form#form2 :input").change(function(){
	    		$("form#form2").data("changed",true);
	    	 })
			 
		 })
    	var id = "";
    	
    	function selectUserType() {
    		$('#dialog').modal({
                keyboard: true
            });
    	}
    	
    	function search(page) {
    		var name = $.trim($("#name").val());
    		var type = $.trim($("#type").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"name":name,"type":type},
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入x`  
    	}
    	
        $(function () {
        	
        	var userIds = "${receUser}";
        	var userIdList = [];
        	if (userIds != null && userIds.length > 0) {
        		userIdList = userIds.split(",");
        	}
        	
        	function checkSelected(id) {
        		if (userIdList.length > 0) {
        			for (var i=0; i<userIdList.length; i++) {
        				if (userIdList[i] == id) {
        					return true;
        				}
        			}
        		}
        		return false;
        	}
        	
            $("#gridlist").jqGrid({
                url: "${ctx}/sysUser/getAllZxUserList.html",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['用户<spring:message code='message.lable.username'/>', '用户<spring:message code='message.lable.userType'/>','',''],
                colModel: [
                    { name: 'name', width: 10, align:"left", sortable: false},
                    { name: 'typeName', width: 5, align:"center", sortable: false },
                    { name: 'orgId', width: 5, align:"center",hidden:true, sortable: false },
                    { name: 'type', width: 5, align:"center",hidden:true, sortable: false }
                   
                ],
                rowNum: 10,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "用户列表",
                jsonReader: {
                    repeatitems: false,
                    id: "id"
                },
                gridComplete:function(){
                	var ids = $("#gridlist").jqGrid('getDataIDs');
                	if (ids.length > 0) {
                		for (var i=0; i<ids.length; i++) {
                			var id = ids[i];
                			if (checkSelected(id)) {
                				$("#gridlist").setSelection(id);
                			}
                		}
                	}
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        
        function batchGroupAddComp(){
        	var userIds = $("#gridlist").jqGrid('getGridParam', 'selarrrow');
        	 if (userIds.length <= 0) {
                 $.HN.message.alert("请选择接收人！", "消息", "error");
                 return;
             }
             var list = [];
             for (var i=0; i<userIds.length; i++) {//获取单条数据信息
            	 var rowdata = $("#gridlist").jqGrid(
							'getRowData', userIds[i]);
                 list.push({"userId":userIds[i],"userName":rowdata.name.replace('<span id="transmark"></span>',''),"orgId":rowdata.orgId,"type":rowdata.type+""});
             }
    		 var dialog = top.dialog.get(window);
        	 dialog.close(list); // 关闭（隐藏）对话框
        	 dialog.remove();				 // 主动销毁对话框
 			return false;
        }
        
        function closeDiv(){
        	var dialog = top.dialog.get(window);
        	 dialog.remove();	
        	 return false;
        }
    </script>
</body>
</html>
